package com.ruoyi.web.controller.mall.orderCom.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.orderCom.domain.OrderCom;
import com.ruoyi.web.controller.mall.orderCom.service.IOrderComService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单返佣Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/orderCom")
public class OrderComController extends BaseController
{
    private String prefix = "mall/orderCom";

    @Autowired
    private IOrderComService orderComService;

//    @RequiresPermissions("mall:orderCom:view")
    @GetMapping()
    public String orderCom()
    {
        return prefix + "/orderCom";
    }

    /**
     * 查询订单返佣列表
     */
//    @RequiresPermissions("mall:orderCom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderCom orderCom)
    {
        startPage();
        List<OrderCom> list = orderComService.selectOrderComList(orderCom);
        return getDataTable(list);
    }

    /**
     * 导出订单返佣列表
     */
//    @RequiresPermissions("mall:orderCom:export")
    @Log(title = "订单返佣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderCom orderCom)
    {
        List<OrderCom> list = orderComService.selectOrderComList(orderCom);
        ExcelUtil<OrderCom> util = new ExcelUtil<OrderCom>(OrderCom.class);
        return util.exportExcel(list, "orderCom");
    }

    /**
     * 新增订单返佣
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单返佣
     */
//    @RequiresPermissions("mall:orderCom:add")
    @Log(title = "订单返佣", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderCom orderCom)
    {
        return toAjax(orderComService.insertOrderCom(orderCom));
    }

    /**
     * 修改订单返佣
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OrderCom orderCom = orderComService.selectOrderComById(id);
        mmap.put("orderCom", orderCom);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单返佣
     */
//    @RequiresPermissions("mall:orderCom:edit")
    @Log(title = "订单返佣", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderCom orderCom)
    {
        return toAjax(orderComService.updateOrderCom(orderCom));
    }

    /**
     * 删除订单返佣
     */
//    @RequiresPermissions("mall:orderCom:remove")
    @Log(title = "订单返佣", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(orderComService.deleteOrderComByIds(ids));
    }
}
